|
|
@@ -9,13 +9,13 @@ module Agents
|
9
|
9
|
The PushoverAgent receives and collects events and sends them via push notification to a user/group.
|
10
|
10
|
|
11
|
11
|
**You need a Pushover API Token:** [https://pushover.net/apps/build](https://pushover.net/apps/build)
|
12
|
|
-
|
|
12
|
+
|
13
|
13
|
**You must provide** a `message` or `text` key that will contain the body of the notification. This can come from an event or be set as a default. Pushover API has a `512` Character Limit including `title`. `message` will be truncated.
|
14
|
14
|
|
15
|
15
|
* `token`: your application's API token
|
16
|
16
|
* `user`: the user or group key (not e-mail address).
|
17
|
17
|
* `expected_receive_period_in_days`: is maximum number of days that you would expect to pass between events being received by this agent.
|
18
|
|
-
|
|
18
|
+
|
19
|
19
|
Your event can provide any of the following optional parameters or you can provide defaults:
|
20
|
20
|
|
21
|
21
|
* `device` - your user's device name to send the message directly to that device, rather than all of the user's devices
|
|
|
@@ -58,7 +58,7 @@ module Agents
|
58
|
58
|
|
59
|
59
|
def receive(incoming_events)
|
60
|
60
|
incoming_events.each do |event|
|
61
|
|
- message = (event.payload['message'] || event.payload['text'] || options['message']).to_s
|
|
61
|
+ message = (event.payload['message'].presence || event.payload['text'].presence || options['message']).to_s
|
62
|
62
|
if message.present?
|
63
|
63
|
post_params = {
|
64
|
64
|
'token' => options['token'],
|
|
|
@@ -66,29 +66,29 @@ module Agents
|
66
|
66
|
'message' => message
|
67
|
67
|
}
|
68
|
68
|
|
69
|
|
- post_params['device'] = event.payload['device'] || options['device']
|
70
|
|
- post_params['title'] = event.payload['title'] || event.payload['subject'] || options['title']
|
71
|
|
-
|
72
|
|
- url = (event.payload['url'] || options['url'] || '').to_s
|
|
69
|
+ post_params['device'] = event.payload['device'].presence || options['device']
|
|
70
|
+ post_params['title'] = event.payload['title'].presence || event.payload['subject'].presence || options['title']
|
|
71
|
+
|
|
72
|
+ url = (event.payload['url'].presence || options['url'] || '').to_s
|
73
|
73
|
url = url.slice 0..512
|
74
|
74
|
post_params['url'] = url
|
75
|
|
-
|
76
|
|
- url_title = (event.payload['url_title'] || options['url_title']).to_s
|
|
75
|
+
|
|
76
|
+ url_title = (event.payload['url_title'].presence || options['url_title']).to_s
|
77
|
77
|
url_title = url_title.slice 0..100
|
78
|
78
|
post_params['url_title'] = url_title
|
79
|
|
-
|
80
|
|
- post_params['priority'] = (event.payload['priority'] || options['priority']).to_i
|
81
|
|
-
|
|
79
|
+
|
|
80
|
+ post_params['priority'] = (event.payload['priority'].presence || options['priority']).to_i
|
|
81
|
+
|
82
|
82
|
if event.payload.has_key? 'timestamp'
|
83
|
83
|
post_params['timestamp'] = (event.payload['timestamp']).to_s
|
84
|
84
|
end
|
85
|
85
|
|
86
|
|
- post_params['sound'] = (event.payload['sound'] || options['sound']).to_s
|
|
86
|
+ post_params['sound'] = (event.payload['sound'].presence || options['sound']).to_s
|
|
87
|
+
|
|
88
|
+ post_params['retry'] = (event.payload['retry'].presence || options['retry']).to_i
|
87
|
89
|
|
88
|
|
- post_params['retry'] = (event.payload['retry'] || options['retry']).to_i
|
|
90
|
+ post_params['expire'] = (event.payload['expire'].presence || options['expire']).to_i
|
89
|
91
|
|
90
|
|
- post_params['expire'] = (event.payload['expire'] || options['expire']).to_i
|
91
|
|
-
|
92
|
92
|
send_notification(post_params)
|
93
|
93
|
end
|
94
|
94
|
end
|